package com.turing.post.cardmanagement.impl;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.turing.post.capitalaccounts.util.CapitalApplicationException;
import com.turing.post.cardmanagement.util.CardClassic;
import com.turing.post.cardmanagement.util.CardClassicBusiness;
import com.turing.post.cardmanagement.util.CardClassicDao;
import com.turing.post.cardmanagement.util.CardManaRespCode;
import com.turing.post.common.util.SysOperLog;
import com.turing.post.common.util.SysOperLogDao;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSWebInput;

@Stateless(mappedName = "cardmanagement.impl.CardClassicBusinessImpl")
@Remote
@Local
public class CardClassicBusinessImpl implements CardClassicBusiness {
	@EJB(mappedName = "cardmanagement.impl.CardClassicDaoImpl")
	private CardClassicDao cardClassicDao;

	@EJB(mappedName = "common.impl.SysOperLogDaoImpl")
	private SysOperLogDao sysOperLogDaoImpl;

	@Override
	public void updateCardClassicInfo(PCPSWebInput webInput,
			CardClassic CardClassic) throws PCPSApplicationException {
		if (CardClassic == null) {
			throw new CapitalApplicationException(
					CapitalApplicationException.ERRMSG_NULLPOINTER,
					CardManaRespCode.RC_ARGS_NULL, "参数为NULL");
		}

		CardClassic cardClassic = cardClassicDao
				.getCardClassicByForUpdate(CardClassic.getCardClassicId());
		if (cardClassic == null) {
			throw new CapitalApplicationException(
					CapitalApplicationException.ERRMSG_NULLPOINTER,
					CardManaRespCode.RC_ARGS_NULL, "参数为NULL");
		}
		if (cardClassicDao.IsCardClassicName(CardClassic.getIssueCompanyNo(),
				CardClassic.getCardClassicName(), CardClassic
						.getCardClassicId()) > 0) {
			throw new CapitalApplicationException(
					CapitalApplicationException.ERRMSG_NULLPOINTER,
					CardManaRespCode.RC_ARGS_NULL, "种类名称:"
							+ CardClassic.getCardClassicName() + " 已经存在");
		}
		cardClassic.setCardClassicName(CardClassic.getCardClassicName());
		cardClassic.setProxyIssueBin(CardClassic.getProxyIssueBin());
		cardClassic.setStatus(CardClassic.getStatus());
		cardClassic.setIsRealName(CardClassic.getIsRealName());
		cardClassic.setAllowDeposit(CardClassic.getAllowDeposit());
		cardClassic.setBalanceLimit(CardClassic.getBalanceLimit());
		cardClassic.setPaidCountLimit(CardClassic.getPaidCountLimit());
		cardClassic.setPaidAmountLowLimit(CardClassic.getPaidAmountLowLimit());
		cardClassic
				.setPaidAmountHighLimit(CardClassic.getPaidAmountHighLimit());
		cardClassic.setAllowRedemp(CardClassic.getAllowRedemp());
		cardClassic.setRemark(CardClassic.getRemark());
		cardClassicDao.updateCardClassic(cardClassic);
		// 日志记录
		sysOperLogDaoImpl.insertSysOperLogInfo(webInput,
				SysOperLog.operType_Add, "修改卡种类", "CardClassicName:"
						+ cardClassic.getCardClassicName());
	}
}